﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using FrameWork;
using FrameWork.Components;
using FrameWork.WebControls;


namespace FrameWork.web.Module.ITMS.KnowledgeBase.KBCollect
{
    public partial class KBGetType : System.Web.UI.Page
    {
        public string TableSink = Common.TableSink;
        //public int KID = (int)Common.sink("KID", MethodType.Get, 255, 1, DataType.Int);
        public int KID = 0;
        //int ToKID = (int)Common.sink("ToKID", MethodType.Get, 255, 0, DataType.Int);
        //string CMD = (string)Common.sink("CMD", MethodType.Get, 255, 0, DataType.Str);

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (CMD == "Move")
            //{
            //    FrameWorkPermission.CheckPermissionVoid(PopedomType.Edit);
            //    //MoveCat();
            //}
            //else
            //{
                OutJs();
            //}
        }

        //private void MoveCat()
        //{

        //    its_KnowledgeBaseKind GT = BusinessFacade.its_KnowledgeBaseKindDisp(KID);
        //    its_KnowledgeBaseKind GTTo = BusinessFacade.its_KnowledgeBaseKindDisp(ToKID);
        //    int K_ParentID = GT.K_ParentID;

        //    //更新移动分类父分类子分类数
        //    BusinessFacade.Update_Table_Fileds("its_KnowledgeBaseKind", "K_ChildCount=K_ChildCount-1", string.Format("KID={0}", K_ParentID));

        //    //更新移动分类
        //    GT.K_ParentID = ToKID;
        //    GT.DB_Option_Action_ = "Update";
        //    GT.K_ShowOrder = GTTo.K_ChildCount + 1;
        //    BusinessFacade.its_KnowledgeBaseKindInsertUpdate(GT);



        //    //更新移动到分类
        //    if (GTTo.KID != 0)
        //    {
        //        GTTo.K_ChildCount++;
        //        GTTo.DB_Option_Action_ = "Update";
        //        BusinessFacade.its_KnowledgeBaseKindInsertUpdate(GTTo);
        //    }

        //    //排序移动到分类
        //    BusinessFacade.its_KnowledgeBaseKind_By(ToKID);

        //    //更新移动分类及子分类层数
        //    string Sub_GroupID = BusinessFacade.GetKindCatID(KID);
        //    string[] Sub_GroupIDArray = Sub_GroupID.Split(',');
        //    for (int i = 0; i < Sub_GroupIDArray.Length; i++)
        //    {
        //        BusinessFacade.Update_Table_Fileds("its_KnowledgeBaseKind", string.Format("K_Level=K_Level+{0}+1-{1}", GTTo.K_Level, GT.K_Level), 
        //            string.Format("KID={0}", Sub_GroupIDArray[i]));
        //    }

        //    //排序当前移动分类的父分类的子分类
        //    BusinessFacade.its_KnowledgeBaseKind_By(K_ParentID);

        //    EventMessage.MessageBox(1, "操作成功", string.Format("移动类别({0})成功!", GT.K_KName), Icon_Type.OK, Common.GetHomeBaseUrl(string.Format("KindList.aspx?KID={0}", ToKID)), Common.BuildJs);


        //}

        private void OutJs()
        {
            int TotalRecord = 0;
            string strLink = "";
            int intCount = 0;

            QueryParam qp = new QueryParam();
            qp.Where = string.Format("Where K_Delete=0");
            qp.Orderfld = "K_Level,K_ShowOrder";
            qp.OrderType = 0;
            ArrayList lst = BusinessFacade.its_KnowledgeBaseKindList(qp, out TotalRecord);
            StringBuilder strSB = new StringBuilder();

            strSB.Append("<script language='JavaScript'>\n");
            //strSB.Append("Fold_id='';\n");

            strSB.Append("treeRoot = gFld(\"mainbody\", \"类别列表\", \"\",\"0\")\n");

            foreach (its_KnowledgeBaseKind x in lst)
            {
                intCount = intCount + 1;
                strLink = x.KID.ToString();
                if (x.K_Level == 1)
                {
                    if (x.K_ChildCount == 0)
                    {

                        strSB.AppendFormat("insDoc(treeRoot,gLnk(\"mainbody\",\"{0}\",\"\",\"{1}\"))\n", Common.ReplaceJs(x.K_KName), strLink);
                    }
                    else
                    {
                        strSB.AppendFormat("N{0}=insFld(treeRoot,gFld(\"mainbody\",\"{1}\",\"\",\"{2}\"))\n", x.KID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                }
                else
                {
                    if (x.K_ChildCount == 0)
                    {
                        strSB.AppendFormat("insDoc(N{0},gLnk(\"mainbody\",\"{1}\",\"\",\"{2}\"))\n", x.K_ParentID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                    else
                    {
                        strSB.AppendFormat("N{0}=insFld(N{1},gFld(\"mainbody\",\"{2}\",\"\",\"{3}\"))\n", x.KID, x.K_ParentID, Common.ReplaceJs(x.K_KName), strLink);
                    }
                }

            }
            
            strSB.Append("	initializeDocument();\n");
            strSB.Append("</script>\n");
            ShowScript.Text = strSB.ToString();

        }
    }
}
